///
/// @ProjectName:    fluro_decorate
/// @Package:
/// @ClassName:      bundle
/// @Description:    Bundle主要用于传递数据；它保存的数据，是以key-value(键值对)的形式存在的。
/// @Author:         WTT
/// @CreateDate:     2021/10/27 2:32 下午
class Bundle {
  /// 存储键值对
  Map<String, dynamic> _map = {};

  /// 存值
  /// [key] 键
  /// [value] 值
  _setValue(String key, dynamic value) => _map[key] = value;

  /// 取值
  /// [key] 键
  _getValue(String key) {
    if (!containsKey(key)) {
      throw Exception("$key不存在");
    }
    return _map[key];
  }

  /// 检查当前Bundle是否包含该key值
  /// [key]
  bool containsKey(String key) {
    return _map.containsKey(key);
  }

  /// 传入路由路径
  /// [routePage] 路由地址
  setRoutePage(String routePage) => _setValue("routePage", routePage);

  /// 保存bool 数据
  /// [key] 键
  /// [value] bool 值
  putBool(String key, bool value) => _setValue(key, value);

  /// 获取bool数据
  bool getBool(String key) => _getValue(key) as bool;

  /// 保存Int 数据
  /// [key] 键
  /// [value] int 值
  putInt(String key, int value) => _setValue(key, value);

  /// 获取Int 数据
  int getInt(String key) => _getValue(key) as int;

  /// 保存Double 数据
  /// [key] 键
  /// [value] double 值
  putDouble(String key, double value) => _setValue(key, value);

  /// 获取Double数据
  double getDouble(String key) => _getValue(key) as double;

  /// 保存String数据
  /// [key] 键
  /// [value] String 值
  putString(String key, String value) => _setValue(key, value);

  /// 获取String值
  String getString(String key) => _getValue(key) as String;

  /// 保存Map 数据
  /// [key] 键
  /// [value] Map<K, V> 值
  putMap<K, V>(String key, Map<K, V> value) => _setValue(key, value);

  /// 获取Map值
  getMap(String key) => _getValue(key) as Map;

  /// 保存List数据
  /// [key] 键
  /// [value] List<V> 值
  putList<V>(String key, List<V> value) => _setValue(key, value);

  /// 获取List值
  getList(String key) => _getValue(key) as List;

  /// 保存对象数据
  /// [key] 键
  /// [value] V 值
  putObject<V>(String key, V value) => _setValue(key, value);

  /// 获取Object值
  V getObject<V>(String key) => _getValue(key) as V;

  /// Bundle默认构造函数
  Bundle();

  /// 带有RoutePage的Bundle构造函数
  Bundle.routePage(String routePage) {
    setRoutePage(routePage);
  }

  @override
  String toString() {
    return _map.toString();
  }
}
